<template>
    <div>
        <!-- <h2>当前最新的count值:{{$store.state.count}}</h2> -->
        <h2>当前最新的count值:{{$store.getters.showNum}}</h2>
        <button @click="btnadd">+1</button>
        <button @click="btnadd2">+10</button>
        <button @click="btnadd3">+1</button>
        <button @click="btnadd4">+1</button>
    </div>
</template>
<script>
export default {
    data () {
        return {
            
        }
    },
    methods: {
        //点击按钮触发add方法
        btnadd() {
            //commit 的作用就是调用 某个mutation 函数
            this.$store.commit('add')
        },
        btnadd2() {
            this.$store.commit('addN',10)
        },
        //异步的让count+1
        btnadd3() {
            //这里的dispatch 专门用来触发action
            this.$store.dispatch('addAsync')
        },
        //异步的让count+N
        btnadd4() {
            this.$store.dispatch('addNasync',6)
        }
    }
}
</script>
<style lang="less" scoped>

</style>